package com.wlyy.bcwlw.sys.user.entity;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.wlyy.bcwlw.sys.SecurityConst;
import com.wlyy.bcwlw.sys.application.entity.ApplicationDTO;
import com.wlyy.bcwlw.sys.menu.entity.MenuDTO;
import com.wlyy.bcwlw.sys.menu.entity.ModuleDTO;
import com.wlyy.bcwlw.sys.permission.entity.PermissionDTO;
import com.wlyy.bcwlw.sys.role.entity.RoleDTO;



public class UserProfile extends UserDTO {
	
	/** 
	* @Fields serialVersionUID : TODO
	*/ 
	private static final long serialVersionUID = 7422323502835987436L;
	
	public UserProfile() {
		// TODO Auto-generated constructor stub
	}
	
	public UserProfile(String userId, String username) {
		super();
		setUserId(userId);
		setUserName(username);
	}
	/**ip地址**/
	private String ip;
	/**浏览器**/
	private String explore;
	/**
	 * 用户角色
	 */
	private List<RoleDTO> roles = new ArrayList<RoleDTO>();
	/**
	 * 用户角色
	 */
	private List<PermissionDTO> permissions = new ArrayList<PermissionDTO>();
	
	/**
	 * 用户应用
	 */
	private List<ApplicationDTO> apps = new ArrayList<ApplicationDTO>();
	
	/**
	 * 用户的模块
	 */
	private List<ModuleDTO> modules = new ArrayList<ModuleDTO>();
	
	/**
	 * 用户菜单
	 */
	private List<MenuDTO> menus = new ArrayList<MenuDTO>();
	
	/**
	 * 用户当前访问系统的菜单
	 */
	private List<MenuDTO> currentAppMenus = new ArrayList<MenuDTO>();
	

	/*
	 * 和递归方法共享的一个变量，即 未关联到树上的节点，会持续递减
	 */
	private List<MenuDTO> remainMenuDTOs;

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getExplore() {
		return explore;
	}

	public void setExplore(String explore) {
		this.explore = explore;
	}

	public List<RoleDTO> getRoles() {
		return roles;
	}
	
	public List<String> getRoleIds() {
		List<String> roleIds = new ArrayList<String>();
		for (Iterator<RoleDTO> iterator = roles.iterator(); iterator.hasNext();) {
			RoleDTO role = (RoleDTO) iterator.next();
			roleIds.add(role.getId());
		}
		return roleIds;
	}

	public void setRoles(List<RoleDTO> roles) {
		this.roles = roles;
	}

	public List<PermissionDTO> getPermissions() {
		return permissions;
	}

	public void setPermissions(List<PermissionDTO> permissions) {
		this.permissions = permissions;
	}
	
	

	public List<ApplicationDTO> getApps() {
		return apps;
	}

	public void setApps(List<ApplicationDTO> apps) {
		this.apps = apps;
	}
	
	

	public List<ModuleDTO> getModules() {
		return modules;
	}

	public void setModules(List<ModuleDTO> modules) {
		this.modules = modules;
	}

	public List<MenuDTO> getMenus() {
		return menus;
	}

	public void setMenus(List<MenuDTO> menus) {
		this.menus = menus;
	}

	public List<MenuDTO> getCurrentAppMenus() {
		return currentAppMenus;
	}

	public void setCurrentAppMenus(List<MenuDTO> currentAppMenus) {
		this.currentAppMenus = currentAppMenus;
	}

	public List<MenuDTO> getRemainMenuDTOs() {
		return remainMenuDTOs;
	}

	public void setRemainMenuDTOs(List<MenuDTO> remainMenuDTOs) {
		this.remainMenuDTOs = remainMenuDTOs;
	}



	
	public static final UserProfile ANONYMOUS = new UserProfile(
			SecurityConst.ANONYMOUS_ID, "anonymous");
	
	public boolean isAnonymous() {
		return SecurityConst.ANONYMOUS_ID.equals(this.getUserId()) || StringUtils.isEmpty(this.getUserId());
	}
	

}
